#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        printf("我是一个子进程:%d\n",getpid());
        sleep(1);
        //让子进程执行程序替换
        execl("/usr/bin/ls","ls","-a","-l","-n",NULL);
        printf("程序替换失败\n");
        exit(1);
    }
    //父进程等待子进程
    pid_t rid = waitpid(id,NULL,0);
    if(rid>0)
    {
        printf("wait:%d success\n",id);
    }
    return 0;
}
